home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
cmln0486.arc
/
MENU.LT1
< prev
next >
Wrap
Text File
|
1986-04-06
|
9KB
|
234 lines
stty -echo; cat - > MEN.C; stty echo
#include "menu_io.c" /* the machine specific routines */
#include "men.h" /* the header file */
main() /* this is just a example 'main' */
{
men_walk(0,0,0);
exit();
}
test() /* part of the example */
{
men_curs(3,20);
men_printf("test");
}
one() /* part of the example */
{
men_curs(3,20);
men_printf("one ");
}
two() /* part of the example */
{
men_curs(3,20);
men_printf("two ");
}
/* the MENU library starts here */
men_disp(n,i)
int n,i;
{
int i2=0; /* helps remember where we are */
men_curs(0,0); /* this is relative to menu "window" */
men_el(); /* erase the top menu line */
men_curs(0,0); /* come on home */
while (i2<men[n].noitems) { /* loop items in current line */
if (i2 == i) standout();/* highlite the indicated item */
men_printf("%s",men[n].items[i2++]);/* print each item */
if (i2 == i+1) standend();/* turn off highlite */
men_printf(" "); /* a little space betwixt items */
}
men_printf("Quit"); /* add the special "quit" item */
}
men_walk(n,n2,i2)
int n,n2,i2; /* n=the menu "line" number, n2=previous menu, i2=previous
highlighted item number */
{
int i,ii; /* need somewhere to remember */
int FINISHED = FALSE;/* set an indicator */
int c,c2; /* for keyboard characters */
i = ii = 0; /* initialization is req'd */
men_disp(n,i); /* put up desired menu line */
while (!(FINISHED)) { /* until user quits explicitly */
menline[0] = 0; /* parameter string gets nulled */
sub_men(n,i,n2,i2); /* put up either sub-menu or help info */
men_curs(0,menlen(n,i)); /* put cursor after highlighted item */
c = men_getc(); /* get the menu selection character */
if (c == '/') { /* this indicates a string parameter is coming */
menfetch(menline,LINE,LINELEN); /* so get a line of input */
men_curs(0,menlen(n,i)); /* put cursor back*/
c = men_getc(); /* get the menu selection character */
}
else if (isdigit(c)) { /* this indicates a numeric parameter */
UNGET = TRUE; /* one way to get portability */
ungotten = c; /* sorry, but I've been caught on this one */
menfetch(menline,NUMERIC,5); /* get a number */
men_curs(0,menlen(n,i)); /* put cursor back */
c = men_getc(); /* get the menu selection character */
}
c2 = NOSELECT; /* set up a flag to look for match */
ii = i; /* remember where we started */
if (isalpha(c)) { /* have we got a letter? */
c2 = men_legal(n,c); /* is it one of the items? */
if (c2 != NOSELECT) { /* if so, lie to fake out case */
i = c2; /* so that the menu selection */
c = '\n'; /* looks like a carraige return */
}
}
switch (c) {
case ' ': /* treat a space like a key right */
case KEY_RIGHT: /* usually, the right arrow key */
unstand(n,i); /* de-select current item */
i++; /* move to the right */
if (i > men[n].noitems) i = 0;/* loop around, if nec */
standout(); /* highlight new item */
men_curs(0,menlen(n,i)); /* put the cursor*/
if (i == men[n].noitems) /* if we're out of items */
men_printf("Quit"); /* add the quit item */
else men_printf("%s",men[n].items[i]); /* print the item */
standend(); /* turn off the highlight */
men_printf(" "); /* space up */
break; /* ta-da */
case 'Q': /* capital Q takes us all the way back */
return('Q');
break;
case 27: /* ESC and lower-case q go back one level */
case 'q':
FINISHED = TRUE; /* this breaks the loop */
break;
case '\r': /* we'll treat these the same way */
case '\n':
if ( men[n].next[i] < 0) { /* if the link < 0 */
/* that means we're at the bottom leaf */
/* and need to call a function */
men_curs(1,0); /* erase the bottom line */
men_el();
men_scp(); /* hang on to the cursor position */
if (men[n].class[i] == DISPLAY); /* display only */
else if (men[n].class[i] == INTEGER) {
/* call the function with an int */
(*func[(men[n].next[i]*-1)])(atoi(menline));
}
else if (men[n].class[i] == STRING) {
/*call it with a string */
(*func[(men[n].next[i]*-1)])(menline);
}
else {
/* otherwise, just call it */
(*func[(men[n].next[i]*-1)])();
}
i = ii; /* go back one level */
men_rcp(); /* restore cursor position */
break;
}
else { /* its a selection but it leads to */
/* another menu line, so we "walk" thru */
/* another level */
if (men_walk(men[n].next[i],n,i) == 'Q')
return('Q'); /* watching for an */
/* absolute QUIT */
men_disp(n,i);/*re-display where we started*/
sub_men(n,i,n2,i2);
}
break;
case KEY_LEFT: /* This is just the inverse of KEY_RIGHT */
unstand(n,i);
if (i == 0) i=men[n].noitems;
else i--;
standout();
men_curs(0,menlen(n,i));
if (i == men[n].noitems)
men_printf("Quit");
else men_printf("%s",men[n].items[i]);
standend();
break;
default: /* something wierd was entered */
beep();
break;
}
}
standend(); /* turn off any dangling stand-outs */
} /* and return to calling program */
sub_men(n,i,n2,i2)
int n,i,n2,i2; /* n,i=current line, current item, n2,i2= previous) */
{
int ii = 0;
men_curs(1,0);
men_el();
if (n != 0) { /* show a little history */
men_curs(1,COLS-10);
men_printf("(%s)",men[n2].items[i2]);
}
men_curs(1,0);
if (men[n].noitems == i) { /* supply the "quit" help */
men_printf("Quit this menu");
}
else if (men[n].next[i] < 0) { /* otherwise, help for selected item */
men_printf("%s",menu_help[(men[n].next[i]*-1)]);
}
else { /* we have to print the whole next menu line */
/* as in 'men_disp()' above */
men_curs(1,0);
n = men[n].next[i];
while (ii<men[n].noitems) {
men_printf("%s ",men[n].items[ii++]);
}
}
}
unstand(n,i) /* print the item i in in menu n */
int n,i;
{
men_curs(0,menlen(n,i));
if (i == men[n].noitems)
men_printf("Quit");
else men_printf("%s",men[n].items[i]);
}
menlen(n,i) /* compute the length of a menu item (plust spacing interval) */
int n,i;
{
int l = 0;
while (i--)
l += strlen(men[n].items[i])+2;
return(l);
}
men_legal(n,c) /* check a character against a line of items */
int n;
char c; /* note we're looking for upper-case */
{
int i = 0;
while (i < men[n].noitems) {
if (men[n].items[i][0] == toupper(c)) return(i);
i++;
}
return(NOSELECT);
}
menfetch(s,ty,l) /* here's where we go when hit with slash or a number */
char s[LINELEN];
int ty,l;
{
s[0] = 0;
men_curs(1,0);
men_el();
men_curs(1,0);
men_printf("ENTER ARGUMENT TO THE FUNCTION :");
men_curs(1,34);
sget(s,l,ty);
return;
}
men_printf("ENTER ARGUMENT TO THE FUNCTION :");
men_curs(1,34);
sget(s,l,ty);
retu